package com.achievement.controller;

import com.achievement.domain.dto.JoinMeetingDTO;
import com.achievement.domain.param.JoinMeetingParam;
import com.achievement.domain.vo.JoinMeetingVO;
import com.achievement.service.IJoinMeetingService;
import com.alibaba.fastjson2.JSONObject;
import com.common.annotation.Anonymous;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "学术交流-参加会议")
@RestController
@RequestMapping("/achievement/joinMeeting")
public class JoinMeetingController extends BaseController {
    @Autowired
    private IJoinMeetingService joinMeetingService;

    @PreAuthorize("@ss.hasPermi('achievement:joinMeeting:list')")
    @ApiOperation("获取参加会议列表")
    @GetMapping("/list")
    public TableDataInfo list(JoinMeetingParam param)
    {
        startPage();
        List<JoinMeetingVO> list = joinMeetingService.selectByPage(param);
        return getDataTable(list);
    }

    /**
     * 左上方统计 通过，退回，待审核
     * @param param 检索参数
     * @return AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('achievement:joinMeeting:list')")
    @ApiOperation(value = "左上方统计 通过，退回，待审核",notes = "左上方统计 通过，退回，待审核")
    @GetMapping(value = "/list-statistics")
    public AjaxResult listStatistics(JoinMeetingParam param)
    {
        List<HashMap<String, Integer>> list =joinMeetingService.listStatistics(param);

        return success(list);
    }

    @PostMapping("/export")
    @PreAuthorize("@ss.hasPermi('achievement:joinMeeting:export')")
    @ApiOperation(value = "参加会议导出", notes = "参加会议导出")
    public void export(HttpServletResponse response, @RequestBody Map<String,Object> requestMap) {
        JoinMeetingParam param = JSONObject.parseObject(JSONObject.toJSONString(requestMap), JoinMeetingParam.class);
        List<String> selectedColumns = (List<String>) requestMap.get("selectedColumns");

        List<JoinMeetingVO> list = joinMeetingService.getListByConditions(param);
        ExcelUtil<JoinMeetingVO> util = new ExcelUtil<>(JoinMeetingVO.class);
        util.showColumn(selectedColumns.toArray(new String[0]));
        util.exportExcel(response, list, "参加会议导出数据");
    }

    /**
     * 获取会议详细信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:joinMeeting:query')")
    @ApiOperation("获取参加会议详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(joinMeetingService.getInfoById(id));
    }

    /**
     * 新增会议
     */
    @PreAuthorize("@ss.hasPermi('achievement:joinMeeting:add')")
    @ApiOperation("新增参加会议")
    @Log(title = "新增参加会议", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody JoinMeetingDTO dto)
    {
        return joinMeetingService.add(dto);
    }

    /**
     * 修改会议
     */
    @PreAuthorize("@ss.hasPermi('achievement:joinMeeting:edit')")
    @ApiOperation("修改参加会议")
    @Log(title = "修改参加会议", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    public AjaxResult edit(@RequestBody JoinMeetingDTO dto)
    {
        return joinMeetingService.update(dto);
    }

    /**
     * 删除会议
     */
    @PreAuthorize("@ss.hasPermi('achievement:joinMeeting:remove')")
    @ApiOperation("删除参加会议")
    @Log(title = "删除参加会议", businessType = BusinessType.DELETE)
    @DeleteMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(joinMeetingService.batchRemove(ids));
    }
}
